<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#49b1f5">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon-180x180-yaowan.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-yaowan.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-yaowan.png">
  <link rel="mask-icon" href="/images/logo-yaowan.svg" color="#49b1f5">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zhouyuqian.com","root":"/","scheme":"Mist","version":"7.7.2","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":"default","style":"flat"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":true,"color":"#49b1f5","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":"ture"},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="使用传统方式在 ZYNQ 上移植 Linux。  reference: https:&#x2F;&#x2F;xilinx-wiki.atlassian.net&#x2F;wiki&#x2F;spaces&#x2F;A&#x2F;pages&#x2F;18841738&#x2F;Getting+Started 硬件平台: PYNQ-Z2 Vivado版本: 2018.2">
<meta property="og:type" content="article">
<meta property="og:title" content="ZYNQ 移植 Linux">
<meta property="og:url" content="https://zhouyuqian.com/2020/03/30/ZYNQ-%E7%A7%BB%E6%A4%8D-Linux/index.html">
<meta property="og:site_name" content="Fitz&#39;s Blog - 快乐学习每一天">
<meta property="og:description" content="使用传统方式在 ZYNQ 上移植 Linux。  reference: https:&#x2F;&#x2F;xilinx-wiki.atlassian.net&#x2F;wiki&#x2F;spaces&#x2F;A&#x2F;pages&#x2F;18841738&#x2F;Getting+Started 硬件平台: PYNQ-Z2 Vivado版本: 2018.2">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://pic.zhouyuqian.com/img/20210727233854.png">
<meta property="og:image" content="https://pic.zhouyuqian.com/img/20210727233855.png">
<meta property="og:image" content="https://pic.zhouyuqian.com/img/20210727233856.png">
<meta property="og:image" content="https://pic.zhouyuqian.com/img/20210727233857.png">
<meta property="og:image" content="https://pic.zhouyuqian.com/img/20210727233858.png">
<meta property="article:published_time" content="2020-03-30T13:10:20.000Z">
<meta property="article:modified_time" content="2020-05-11T15:38:53.000Z">
<meta property="article:author" content="Fitz">
<meta property="article:tag" content="FPGA">
<meta property="article:tag" content="ZYNQ">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://pic.zhouyuqian.com/img/20210727233854.png">

<link rel="canonical" href="https://zhouyuqian.com/2020/03/30/ZYNQ-%E7%A7%BB%E6%A4%8D-Linux/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>ZYNQ 移植 Linux | Fitz's Blog - 快乐学习每一天</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Fitz's Blog - 快乐学习每一天</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-ariang">

    <a href="/AriaNg/" rel="section"><i class="fa fa-fw fa-cloud-download"></i>AriaNg</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/Starrynightzyq" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://zhouyuqian.com/2020/03/30/ZYNQ-%E7%A7%BB%E6%A4%8D-Linux/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Fitz">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Fitz's Blog - 快乐学习每一天">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ZYNQ 移植 Linux
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-30 21:10:20" itemprop="dateCreated datePublished" datetime="2020-03-30T21:10:20+08:00">2020-03-30</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-11 23:38:53" itemprop="dateModified" datetime="2020-05-11T23:38:53+08:00">2020-05-11</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ZYNQ-%E7%A7%BB%E6%A4%8D-Linux/" itemprop="url" rel="index"><span itemprop="name">ZYNQ 移植 Linux</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>9.2k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>8 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>使用传统方式在 ZYNQ 上移植 Linux。</p>
<blockquote>
<p>reference: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841738/Getting+Started</p>
<p>硬件平台: <a target="_blank" rel="noopener" href="http://www.tul.com.tw/ProductsPYNQ-Z2.html">PYNQ-Z2</a></p>
<p>Vivado版本: 2018.2</p>
</blockquote>
<a id="more"></a>
<h1 id="vivado-工程创建">Vivado 工程创建</h1>
<p>创建一个 zynq 的 vivado 工程，最小系统就行了，blockdesign 如图：</p>
<figure>
<img src="https://pic.zhouyuqian.com/img/20210727233854.png" alt="blockdesign"><figcaption aria-hidden="true">blockdesign</figcaption>
</figure>
<p>这里添加了一个 AXI-GPIO，是为了后面练习驱动。</p>
<p>生成 bitstream 后，导出到 sdk。</p>
<h1 id="下载需要的资源">下载需要的资源</h1>
<table>
<colgroup>
<col style="width: 3%">
<col style="width: 43%">
<col style="width: 52%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th><strong>Repository Name</strong></th>
<th><strong>Content</strong></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1</td>
<td>https://github.com/Xilinx/linux-xlnx.git</td>
<td>The Linux kernel with Xilinx patches and drivers</td>
</tr>
<tr class="even">
<td>2</td>
<td>https://github.com/Xilinx/u-boot-xlnx.git</td>
<td>The u-boot bootloader with Xilinx patches and drivers</td>
</tr>
<tr class="odd">
<td>3</td>
<td>https://github.com/Xilinx/device-tree-xlnx.git</td>
<td>Device Tree generator plugin for xsdk</td>
</tr>
<tr class="even">
<td>4</td>
<td>https://git.kernel.org/pub/scm/utils/dtc/dtc.git</td>
<td>Device Tree compiler (required to build U-Boot)</td>
</tr>
<tr class="odd">
<td>5</td>
<td>https://github.com/Xilinx/arm-trusted-firmware.git</td>
<td>ARM Trusted Firmware (required for Zynq UltraScale+ MPSoC and Versal platforms)</td>
</tr>
<tr class="even">
<td>6</td>
<td>https://github.com/Xilinx/xen.git</td>
<td>Xilinx Xen branch for Zynq UltraScale+ and Versal platforms</td>
</tr>
<tr class="odd">
<td>7</td>
<td>https://github.com/Xilinx/embeddedsw.git</td>
<td>Xilinx embeddedsw repository for bare-metal applications such as FSBL, PMU Firmware, PLM</td>
</tr>
</tbody>
</table>
<h1 id="配置环境">配置环境</h1>
<h2 id="build-device-tree-compiler-dtc">Build Device Tree Compiler (dtc)</h2>
<blockquote>
<p>Tools Required: vivado sdk</p>
<p>Source Required: <a target="_blank" rel="noopener" href="https://git.kernel.org/pub/scm/utils/dtc/dtc.git">Device Tree compiler</a></p>
</blockquote>
<p>下载<a target="_blank" rel="noopener" href="https://git.kernel.org/pub/scm/utils/dtc/dtc.git">Device Tree compiler</a>，在目录 <em>dtc</em> 下运行：</p>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">make</span></span><br></pre></td></tr></table></figure>
<p>会在当前目录生成 <code>dtc</code>，一个可执行文件，将其添加到 PATH 中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=`<span class="built_in">pwd</span>`:<span class="variable">$PATH</span> <span class="comment"># 或者把 `pwd` 换为 &lt;dtc&gt; 目录</span></span><br></pre></td></tr></table></figure>
<h2 id="其他">其他</h2>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># export PATH=/home/fitz/linux-on-zynq/linux-xlnx/scripts/dtc:$PATH</span></span><br><span class="line"><span class="built_in">export</span> PATH=/home/fitz/linux-on-zynq/dtc:<span class="variable">$PATH</span></span><br><span class="line"><span class="built_in">export</span> PATH=/home/fitz/linux-on-zynq/u-boot-xlnx/tools:<span class="variable">$PATH</span></span><br><span class="line"><span class="built_in">export</span> CROSS_COMPILE=arm-linux-gnueabihf-</span><br><span class="line"><span class="built_in">export</span> ARCH=arm</span><br></pre></td></tr></table></figure>
<h1 id="创建设备树文件">创建设备树文件</h1>
<blockquote>
<p>Tools Required: vivado sdk</p>
<p>Source Required: <a target="_blank" rel="noopener" href="https://github.com/Xilinx/device-tree-xlnx.git">device-tree-xlnx</a></p>
</blockquote>
<p>下载与 vivado 版本对应的 device-tree-xlnx</p>
<p>在 vivado sdk 中添加设备树插件：</p>
<p>SDK Menu: Xilinx &gt; Repositories &gt; New… <code>&lt;device-tree-xlnx&gt;</code> &gt; OK</p>
<figure>
<img src="https://pic.zhouyuqian.com/img/20210727233855.png" alt="add-repositories"><figcaption aria-hidden="true">add-repositories</figcaption>
</figure>
<p>然后创建一个 BSP，选择 device_tree 模板：</p>
<figure>
<img src="https://pic.zhouyuqian.com/img/20210727233856.png" alt="bsp"><figcaption aria-hidden="true">bsp</figcaption>
</figure>
<p>生成的 .dts/.dtsi 在 <em>/device_tree_bsp_0/ folder</em> 目录下，会使用到文件有：<em>system-top.dts, pcw.dtsi, pl.dtsi</em></p>
<p>这几个文件在后面编译 u-boot 的时候会用到，在编译 u-boot 的时候同时生成 .dtb</p>
<h1 id="编译-u-boot-编译设备树">编译 U-BOOT &amp; 编译设备树</h1>
<blockquote>
<p>Tools Required: vivado sdk</p>
<p>Source Required: <a target="_blank" rel="noopener" href="https://github.com/Xilinx/device-tree-xlnx.git">u-boot-xlnx</a></p>
</blockquote>
<p>下载与 vivado 版本对应的 u-boot-xlnx，需要创建/修改 4 个文件：</p>
<ol type="1">
<li><p><em>u-boot-xlnx/include/configs/zynq_pynqz2.h</em>（新建）</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> __CONFIG_ZYNQ_PYNQZ2_H</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __CONFIG_ZYNQ_PYNQZ2_H</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CONFIG_ZYNQ_I2C0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* Define PYNQZ2 PS Clock Frequency to 50MHz */</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CONFIG_ZYNQ_PS_CLK_FREQ 50000000UL</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;configs/zynq-common.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span> <span class="comment">/* __CONFIG_ZYNQ_PYNQZ2_H */</span></span></span><br></pre></td></tr></table></figure>
<p>这里面定义了 PS 时钟频率 50 MHz</p></li>
<li><p><em>u-boot-xlnx/include/configs/zynq-common.h</em>（修改）</p>
<p>将：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;sdboot=if mmcinfo; then &quot;</span> \</span><br><span class="line">        <span class="string">&quot;run uenvboot; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;echo Copying Linux from SD to RAM... &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;load mmc 0 $&#123;kernel_load_address&#125; $&#123;kernel_image&#125; &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;load mmc 0 $&#123;devicetree_load_address&#125; $&#123;devicetree_image&#125; &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;load mmc 0 $&#123;ramdisk_load_address&#125; $&#123;ramdisk_image&#125; &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;bootm $&#123;kernel_load_address&#125; $&#123;ramdisk_load_address&#125; $&#123;devicetree_load_address&#125;; &quot;</span> \</span><br><span class="line">    <span class="string">&quot;fi\0&quot;</span> \</span><br></pre></td></tr></table></figure>
<p>改为：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;sdboot=if mmcinfo; then &quot;</span> \</span><br><span class="line">        <span class="string">&quot;run uenvboot; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;echo Copying Linux from SD to RAM... &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;load mmc 0 $&#123;kernel_load_address&#125; $&#123;kernel_image&#125; &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;load mmc 0 $&#123;devicetree_load_address&#125; $&#123;devicetree_image&#125; &amp;&amp; &quot;</span> \</span><br><span class="line">        <span class="string">&quot;bootm $&#123;kernel_load_address&#125; - $&#123;devicetree_load_address&#125;; &quot;</span> \</span><br><span class="line">    <span class="string">&quot;fi\0&quot;</span> \</span><br></pre></td></tr></table></figure>
<p>修改 sboot 这段，这段表示从 SD 卡启动时，文件加载的情况，我们将文件系统放在了 SD 卡的第二个分区，因此不需要 load ramdisk，这里的 <code>-</code> 号，左右都要有空格，意思是替代的地址，那么就要把 <code>-</code> 作为 <code>$&#123;ramdisk_load_address&#125;</code> 的替代，告诉 u-boot 和内核没有文件系统，启动的时候就不会加载它。</p></li>
<li><p><em>u-boot-xlnx/configs/zynq_pynqz2_defconfig</em></p>
<p><em>zynq_pynqz2_defconfig</em> 可以参考同目录下的 <em>u-boot-xlnx/configs/zynq_zybo_defconfig</em>，稍作修改：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line">CONFIG_ARM=y</span><br><span class="line">CONFIG_SYS_CONFIG_NAME=<span class="string">&quot;zynq_pynqz2&quot;</span></span><br><span class="line">CONFIG_ARCH_ZYNQ=y</span><br><span class="line">CONFIG_SYS_TEXT_BASE=<span class="number">0x4000000</span></span><br><span class="line">CONFIG_SPL_STACK_R_ADDR=<span class="number">0x200000</span></span><br><span class="line">CONFIG_DEFAULT_DEVICE_TREE=<span class="string">&quot;zynq-pynqz2&quot;</span></span><br><span class="line">CONFIG_DEBUG_UART=y</span><br><span class="line">CONFIG_DISTRO_DEFAULTS=y</span><br><span class="line">CONFIG_FIT=y</span><br><span class="line">CONFIG_FIT_VERBOSE=y</span><br><span class="line">CONFIG_FIT_SIGNATURE=y</span><br><span class="line">CONFIG_BOOTCOMMAND=<span class="string">&quot;run $modeboot || run distro_bootcmd&quot;</span></span><br><span class="line"># CONFIG_DISPLAY_CPUINFO is <span class="keyword">not</span> <span class="built_in">set</span></span><br><span class="line">CONFIG_SPL=y</span><br><span class="line">CONFIG_SPL_STACK_R=y</span><br><span class="line">CONFIG_SPL_OS_BOOT=y</span><br><span class="line">CONFIG_SPL_DM_MMC=y</span><br><span class="line">CONFIG_SYS_PROMPT=<span class="string">&quot;Zynq&gt; &quot;</span></span><br><span class="line">CONFIG_CMD_THOR_DOWNLOAD=y</span><br><span class="line">CONFIG_CMD_DFU=y</span><br><span class="line">CONFIG_CMD_FPGA_LOADBP=y</span><br><span class="line">CONFIG_CMD_FPGA_LOADFS=y</span><br><span class="line">CONFIG_CMD_FPGA_LOADMK=y</span><br><span class="line">CONFIG_CMD_FPGA_LOADP=y</span><br><span class="line">CONFIG_CMD_GPIO=y</span><br><span class="line">CONFIG_CMD_I2C=y</span><br><span class="line">CONFIG_CMD_MMC=y</span><br><span class="line">CONFIG_CMD_SF=y</span><br><span class="line">CONFIG_CMD_USB=y</span><br><span class="line"># CONFIG_CMD_SETEXPR is <span class="keyword">not</span> <span class="built_in">set</span></span><br><span class="line">CONFIG_CMD_TFTPPUT=y</span><br><span class="line">CONFIG_CMD_CACHE=y</span><br><span class="line">CONFIG_CMD_EXT4_WRITE=y</span><br><span class="line">CONFIG_OF_EMBED=y</span><br><span class="line">CONFIG_ENV_IS_IN_SPI_FLASH=y</span><br><span class="line">CONFIG_NET_RANDOM_ETHADDR=y</span><br><span class="line">CONFIG_SPL_DM_SEQ_ALIAS=y</span><br><span class="line">CONFIG_DFU_MMC=y</span><br><span class="line">CONFIG_DFU_RAM=y</span><br><span class="line">CONFIG_FPGA_XILINX=y</span><br><span class="line">CONFIG_DM_GPIO=y</span><br><span class="line">CONFIG_MMC=y</span><br><span class="line">CONFIG_MMC_SDHCI=y</span><br><span class="line">CONFIG_MMC_SDHCI_ZYNQ=y</span><br><span class="line">CONFIG_SPI_FLASH=y</span><br><span class="line">CONFIG_SPI_FLASH_BAR=y</span><br><span class="line">CONFIG_SPI_FLASH_SPANSION=y</span><br><span class="line">CONFIG_PHY_MARVELL=y</span><br><span class="line">CONFIG_PHY_REALTEK=y</span><br><span class="line">CONFIG_PHY_XILINX=y</span><br><span class="line">CONFIG_ZYNQ_GEM=y</span><br><span class="line">CONFIG_ZYNQ_GEM_SPI_MAC_OFFSET=<span class="number">0x20</span></span><br><span class="line">CONFIG_DEBUG_UART_ZYNQ=y</span><br><span class="line">CONFIG_DEBUG_UART_BASE=<span class="number">0xe0000000</span></span><br><span class="line">CONFIG_DEBUG_UART_CLOCK=<span class="number">50000000</span></span><br><span class="line">CONFIG_ZYNQ_SERIAL=y</span><br><span class="line">CONFIG_ZYNQ_QSPI=y</span><br><span class="line">CONFIG_USB=y</span><br><span class="line">CONFIG_USB_EHCI=y</span><br><span class="line">CONFIG_USB_EHCI_HCD=y</span><br><span class="line">CONFIG_USB_EHCI_ZYNQ=y</span><br><span class="line">CONFIG_USB_ULPI_VIEWPORT=y</span><br><span class="line">CONFIG_USB_ULPI=y</span><br><span class="line">CONFIG_USB_STORAGE=y</span><br><span class="line">CONFIG_USB_GADGET=y</span><br><span class="line">CONFIG_USB_GADGET_MANUFACTURER=<span class="string">&quot;Xilinx&quot;</span></span><br><span class="line">CONFIG_USB_GADGET_VENDOR_NUM=<span class="number">0x03fd</span></span><br><span class="line">CONFIG_USB_GADGET_PRODUCT_NUM=<span class="number">0x0300</span></span><br><span class="line">CONFIG_CI_UDC=y</span><br><span class="line">CONFIG_USB_GADGET_DOWNLOAD=y</span><br></pre></td></tr></table></figure>
<p>在这里指定了 device tree，因此需要将前一个步骤中生成的 <em>system-top.dts, pcw.dtsi, pl.dtsi</em> 复制到 <em>u-boot-xlnx/arch/arm/dts/</em> 目录下，将 <em>system-top.dts</em> 改名为 <em>zynq-pynqz2.dts</em></p></li>
</ol>
<p>在完成这些后，就可以编译 u-boot 了，运行命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">make distclean</span><br><span class="line">make zynq_pynqz2_defconfig</span><br><span class="line">make <span class="comment"># 或者 make -j8</span></span><br></pre></td></tr></table></figure>
<p>会在 <em>u-boot-xlnx/</em> 目录下生成 <em>u-boot</em> 文件，将其改名为 <em>u-boot.elf</em> 待用，更新一些版本的 vivado 可以直接生成 <em>u-boot.elf</em> 文件。</p>
<p>同时在 <em>arch/arm/dts/</em> 目录下生成 <em>zynq-pynqz2.dtb</em> 文件，即编译好的设备树文件，将其改名为 <em>devicetree.dtb</em> 待用。</p>
<blockquote>
<p>设备树也可以单独编译，命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dtc -I dts -O dtb -o devicetree.dtb system-top.dts</span><br></pre></td></tr></table></figure>
<p><em>devicetree.dtb</em> 为生成的 dtb 文件名字/路径，<em>system-top.dts</em> 为待编译的设备树文件</p>
</blockquote>
<h1 id="创建-boot.bin">创建 BOOT.bin</h1>
<blockquote>
<p>Tools Required: vivado sdk</p>
</blockquote>
<p>首先用 vivado sdk 生成 fsbl，即新建一个 <code>Application Project</code>，选择 <code>Zynq FSBL</code> 模板：</p>
<figure>
<img src="https://pic.zhouyuqian.com/img/20210727233857.png" alt="fsbl"><figcaption aria-hidden="true">fsbl</figcaption>
</figure>
<p>然后在这个 Project 上右击 &gt; Create Boot Image</p>
<figure>
<img src="https://pic.zhouyuqian.com/img/20210727233858.png" alt="Create-Boot-Image"><figcaption aria-hidden="true">Create-Boot-Image</figcaption>
</figure>
<p>依次添加 <em>fsbl.elf, .bit, u-boot.elf</em>，其中的 <em>u-boot.elf</em> 是在上一个步骤中生成的，最后点击 <code>Create Image</code>，会在 <em><vivado_project>/<vivado_project>.sdk/fsbl/bootimage/</vivado_project></vivado_project></em> 目录下生成 <em>BOOT.bin</em> 文件。</p>
<h1 id="编译内核">编译内核</h1>
<blockquote>
<p>Tools Required: vivado sdk</p>
<p>Source Required: <a target="_blank" rel="noopener" href="https://github.com/Xilinx/linux-xlnx.git">linux-xlnx</a></p>
</blockquote>
<p>在目录 <em>linux-xlnx</em> 下，运行命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">make xilinx_zynq_defconfig</span><br><span class="line">make -j8</span><br><span class="line">make UIMAGE_LOADADDR=0x8000 uImage -j8</span><br></pre></td></tr></table></figure>
<p>编译完成后，在目录 <em>linux-xlnx/arch/arm/boot/</em> 下生成未经压缩过的内核镜像 <em>uImage</em> 文件。</p>
<blockquote>
<p>下载不同版本的 <em>linux-xlnx</em>，编译后可以得到不同内核版本</p>
</blockquote>
<h1 id="环境变量文件">环境变量文件</h1>
<p>创建一个名为 <em>uEnv.txt</em> 的文件，内容如下：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">bootargs</span>=console=ttyPS0,115200n8 <span class="attribute">root</span>=/dev/mmcblk0p2 rw noinitrd earlyprintk <span class="attribute">rootfstype</span>=ext4 rootwait devtmpfs.<span class="attribute">mount</span>=0</span><br></pre></td></tr></table></figure>
<p>这里面是系统启动时传给内核的参数，</p>
<p><code>console=ttyPS0,115200n8</code> 表示控制台的串口号；</p>
<p><code>root=/dev/mmcblk0p2 rw noinitrd rootfstype=ext4</code> 配合之前对 <em>u-boot-xlnx/include/configs/zynq-common.h</em> 的修改，实现了从 SD 的第二分区读取文件系统，该分区为 ext4 格式；</p>
<h1 id="最后">最后</h1>
<blockquote>
<p>Source Required: <a target="_blank" rel="noopener" href="https://releases.linaro.org/archive/12.09/ubuntu/precise-images/ubuntu-desktop/linaro-precise-ubuntu-desktop-20120923-436.tar.gz">linaro 文件系统</a></p>
</blockquote>
<p>将 SD 分两个区，第一个区 200M，为 FAT32 格式，剩余容量给第二个分区，为 ext4 格式。</p>
<p>将前几步得到的 <em>BOOT.bin, devicetree.dtb, uImage, uEnv.txt</em> 拷贝到 SD 卡的 FAT32 分区中；</p>
<p>将下载的 <a target="_blank" rel="noopener" href="https://releases.linaro.org/archive/12.09/ubuntu/precise-images/ubuntu-desktop/linaro-precise-ubuntu-desktop-20120923-436.tar.gz">linaro 文件系统</a> 解压，将 <em>binary/boot/filesystem.dir</em> 目录下的文件拷贝到 ext4 分区中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rsync -a --progress ./ /media/fitz/sandisk</span><br></pre></td></tr></table></figure>
<p>最后，将 SD 卡插回板子上，板子上的条线帽选择 SD 卡启动，打开电源，连上串口线，可以看到串口输出如下信息，表示启动成功：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">U-Boot</span> <span class="number">2017.01</span><span class="string">-dirty</span> <span class="string">(Mar</span> <span class="number">31</span> <span class="number">2020</span> <span class="bullet">-</span> <span class="number">17</span><span class="string">:21:17</span> <span class="string">+0800)</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Model:</span> <span class="string">Zynq</span> <span class="string">pynq</span> <span class="string">z2</span> <span class="string">Development</span> <span class="string">Board</span></span><br><span class="line"><span class="attr">Board:</span> <span class="string">Xilinx</span> <span class="string">Zynq</span></span><br><span class="line"><span class="attr">I2C:</span>   <span class="string">ready</span></span><br><span class="line"><span class="attr">DRAM:</span>  <span class="string">ECC</span> <span class="string">disabled</span> <span class="number">512</span> <span class="string">MiB</span></span><br><span class="line"><span class="attr">MMC:</span>   <span class="string">sdhci@e0100000:</span> <span class="number">0</span> <span class="string">(SD)</span></span><br><span class="line"><span class="attr">SF:</span> <span class="string">Detected</span> <span class="string">s25fl128s_64k</span> <span class="string">with</span> <span class="string">page</span> <span class="string">size</span> <span class="number">256</span> <span class="string">Bytes,</span> <span class="string">erase</span> <span class="string">size</span> <span class="number">64</span> <span class="string">KiB,</span> <span class="string">total</span> <span class="number">16</span> <span class="string">MiB</span></span><br><span class="line"><span class="string">***</span> <span class="string">Warning</span> <span class="bullet">-</span> <span class="string">bad</span> <span class="string">CRC,</span> <span class="string">using</span> <span class="string">default</span> <span class="string">environment</span></span><br><span class="line"></span><br><span class="line"><span class="attr">In:</span>    <span class="string">serial@e0000000</span></span><br><span class="line"><span class="attr">Out:</span>   <span class="string">serial@e0000000</span></span><br><span class="line"><span class="attr">Err:</span>   <span class="string">serial@e0000000</span></span><br><span class="line"><span class="attr">Model:</span> <span class="string">Zynq</span> <span class="string">pynq</span> <span class="string">z2</span> <span class="string">Development</span> <span class="string">Board</span></span><br><span class="line"><span class="attr">Board:</span> <span class="string">Xilinx</span> <span class="string">Zynq</span></span><br><span class="line"><span class="attr">Net:   ZYNQ GEM:</span> <span class="string">e000b000,</span> <span class="string">phyaddr</span> <span class="string">ffffffff,</span> <span class="string">interface</span> <span class="string">rgmii-id</span></span><br><span class="line"><span class="attr">eth0:</span> <span class="string">ethernet@e000b000</span></span><br><span class="line"><span class="string">reading</span> <span class="string">uEnv.txt</span></span><br><span class="line"><span class="number">119</span> <span class="string">bytes</span> <span class="string">read</span> <span class="string">in</span> <span class="number">8</span> <span class="string">ms</span> <span class="string">(13.7</span> <span class="string">KiB/s)</span></span><br><span class="line"><span class="string">Importing</span> <span class="string">environment</span> <span class="string">from</span> <span class="string">SD</span> <span class="string">...</span></span><br><span class="line"><span class="attr">Hit any key to stop autoboot:</span>  <span class="number">0</span></span><br><span class="line"><span class="attr">Device:</span> <span class="string">sdhci@e0100000</span></span><br><span class="line"><span class="attr">Manufacturer ID:</span> <span class="number">3</span></span><br><span class="line"><span class="attr">OEM:</span> <span class="number">5344</span></span><br><span class="line"><span class="attr">Name:</span> <span class="string">SC16G</span></span><br><span class="line"><span class="attr">Tran Speed:</span> <span class="number">50000000</span></span><br><span class="line"><span class="attr">Rd Block Len:</span> <span class="number">512</span></span><br><span class="line"><span class="string">SD</span> <span class="string">version</span> <span class="number">3.0</span></span><br><span class="line"><span class="attr">High Capacity:</span> <span class="literal">Yes</span></span><br><span class="line"><span class="attr">Capacity:</span> <span class="number">14.8</span> <span class="string">GiB</span></span><br><span class="line"><span class="attr">Bus Width:</span> <span class="number">4</span><span class="string">-bit</span></span><br><span class="line"><span class="attr">Erase Group Size:</span> <span class="number">512</span> <span class="string">Bytes</span></span><br><span class="line"><span class="string">reading</span> <span class="string">uEnv.txt</span></span><br><span class="line"><span class="number">119</span> <span class="string">bytes</span> <span class="string">read</span> <span class="string">in</span> <span class="number">8</span> <span class="string">ms</span> <span class="string">(13.7</span> <span class="string">KiB/s)</span></span><br><span class="line"><span class="string">Loaded</span> <span class="string">environment</span> <span class="string">from</span> <span class="string">uEnv.txt</span></span><br><span class="line"><span class="string">Importing</span> <span class="string">environment</span> <span class="string">from</span> <span class="string">SD</span> <span class="string">...</span></span><br><span class="line"><span class="string">Copying</span> <span class="string">Linux</span> <span class="string">from</span> <span class="string">SD</span> <span class="string">to</span> <span class="string">RAM...</span></span><br><span class="line"><span class="string">reading</span> <span class="string">uImage</span></span><br><span class="line"><span class="number">3745912</span> <span class="string">bytes</span> <span class="string">read</span> <span class="string">in</span> <span class="number">325</span> <span class="string">ms</span> <span class="string">(11</span> <span class="string">MiB/s)</span></span><br><span class="line"><span class="string">reading</span> <span class="string">devicetree.dtb</span></span><br><span class="line"><span class="number">9958 </span><span class="string">bytes</span> <span class="string">read</span> <span class="string">in</span> <span class="number">14</span> <span class="string">ms</span> <span class="string">(694.3</span> <span class="string">KiB/s)</span></span><br><span class="line"><span class="comment">## Booting kernel from Legacy Image at 02080000 ...</span></span><br><span class="line">   <span class="attr">Image Name:</span>   <span class="string">Linux-4.9.0-xilinx</span></span><br><span class="line">   <span class="attr">Image Type:</span>   <span class="string">ARM</span> <span class="string">Linux</span> <span class="string">Kernel</span> <span class="string">Image</span> <span class="string">(uncompressed)</span></span><br><span class="line">   <span class="attr">Data Size:</span>    <span class="number">3745848</span> <span class="string">Bytes</span> <span class="string">=</span> <span class="number">3.6</span> <span class="string">MiB</span></span><br><span class="line">   <span class="attr">Load Address:</span> <span class="number">00008000</span></span><br><span class="line">   <span class="attr">Entry Point:</span>  <span class="number">00008000</span></span><br><span class="line">   <span class="string">Verifying</span> <span class="string">Checksum</span> <span class="string">...</span> <span class="string">OK</span></span><br><span class="line"><span class="comment">## Flattened Device Tree blob at 02000000</span></span><br><span class="line">   <span class="string">Booting</span> <span class="string">using</span> <span class="string">the</span> <span class="string">fdt</span> <span class="string">blob</span> <span class="string">at</span> <span class="number">0x2000000</span></span><br><span class="line">   <span class="string">Loading</span> <span class="string">Kernel</span> <span class="string">Image</span> <span class="string">...</span> <span class="string">OK</span></span><br><span class="line">   <span class="string">Loading</span> <span class="string">Device</span> <span class="string">Tree</span> <span class="string">to</span> <span class="string">1eb1e000,</span> <span class="string">end</span> <span class="string">1eb236e5</span> <span class="string">...</span> <span class="string">OK</span></span><br><span class="line"></span><br><span class="line"><span class="string">Starting</span> <span class="string">kernel</span> <span class="string">...</span></span><br><span class="line"></span><br><span class="line"><span class="string">...</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Last login:</span> <span class="string">Thu</span> <span class="string">Jan</span>  <span class="number">1</span> <span class="number">00</span><span class="string">:00:06</span> <span class="string">UTC</span> <span class="number">1970 </span><span class="string">on</span> <span class="string">tty1</span></span><br><span class="line"><span class="attr">cat: /var/lib/update-notifier/fsck-at-reboot:</span> <span class="literal">No</span> <span class="string">such</span> <span class="string">file</span> <span class="string">or</span> <span class="string">directory</span></span><br><span class="line"><span class="attr">run-parts:</span> <span class="string">/etc/update-motd.d/98-fsck-at-reboot</span> <span class="string">exited</span> <span class="string">with</span> <span class="string">return</span> <span class="string">code</span> <span class="number">1</span></span><br><span class="line"><span class="string">Welcome</span> <span class="string">to</span> <span class="string">Linaro</span> <span class="number">12.09</span> <span class="string">(GNU/Linux</span> <span class="number">5.4</span><span class="number">.0</span><span class="string">-xilinx-28096-gef412ed37999</span> <span class="string">armv7l)</span></span><br><span class="line"></span><br><span class="line"> <span class="string">*</span> <span class="attr">Documentation:</span>  <span class="string">https://wiki.linaro.org/</span></span><br><span class="line"><span class="string">root@linaro-ubuntu-desktop:~#</span></span><br></pre></td></tr></table></figure>
<h1 id="坑">坑</h1>
<ol type="1">
<li><p>在 build device tree 时，报错：</p>
<figure class="highlight crmsh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">devicetree.dtb: Warning (unit_address_vs_reg): <span class="keyword">Node</span> <span class="title">/memory</span> has a reg <span class="keyword">or</span> ranges <span class="keyword">property</span><span class="title"></span>, but no unit name</span><br></pre></td></tr></table></figure>
<p>解决办法：</p>
<ol type="1">
<li><p><del>dtc 版本与 vivado sdk 版本不对应，换成对应版本的 dtc 就行</del></p></li>
<li><p>修改 <em>system-top.dts</em> 中的 <code>memory</code>：</p>
<p>将：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">memory &#123;</span><br><span class="line">device_type = <span class="string">&quot;memory&quot;</span><span class="comment">;</span></span><br><span class="line"><span class="attribute">reg</span> = &lt;<span class="number">0</span>x0 <span class="number">0</span>x20000000&gt;<span class="comment">;</span></span><br><span class="line">&#125;<span class="comment">;</span></span><br></pre></td></tr></table></figure>
<p>改为：</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="class">memory@0 </span>&#123;</span><br><span class="line">device_type = <span class="string">&quot;memory&quot;</span>;</span><br><span class="line">reg = <span class="params">&lt;<span class="number">0x0</span> <span class="number">0x20000000</span>&gt;</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></li>
</ol></li>
<li><p>Linux 启动时内存分配失败：</p>
<p>启动时串口输出类似信息：</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">U</span>-Boot <span class="number">2017</span>.<span class="number">01</span>-dirty (Mar <span class="number">31</span> <span class="number">2020</span> - <span class="number">17</span>:<span class="number">21</span>:<span class="number">17</span> +<span class="number">0800</span>)</span><br><span class="line"></span><br><span class="line"><span class="attribute">Model</span>: Zynq pynq z<span class="number">2</span> Development Board</span><br><span class="line"><span class="attribute">Board</span>: Xilinx Zynq</span><br><span class="line"><span class="attribute">I2C</span>:   ready</span><br><span class="line"><span class="attribute">DRAM</span>:  ECC disabled <span class="number">0</span> MiB</span><br><span class="line"><span class="attribute">MMC</span>:   sdhci@e<span class="number">0100000</span>: <span class="number">0</span> (SD)</span><br><span class="line"><span class="attribute">SF</span>: Detected s<span class="number">25</span>fl<span class="number">128</span>s_<span class="number">64</span>k with page size <span class="number">256</span> Bytes, erase size <span class="number">64</span> KiB, total <span class="number">16</span> MiB</span><br></pre></td></tr></table></figure>
<p>可以看到 DRAM 为 0，应该是修改 <em>u-boot-xlnx/include/configs/zynq-common.h</em> 或 <em>u-boot-xlnx/include/configs/zynq_pynqz2.h</em> 的问题，DRAM 的大小应该在设备树文件里面的 <code>memory</code> 定义，不要在 <em>zynq-common.h</em> 里面用 <code>#define CONFIG_SYS_SDRAM_SIZE (512 * 1024 * 1024)</code> 定义。</p></li>
</ol>

    </div>

    
    
    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------The end of this article&nbsp;<i class="fa fa-paw"></i>&nbsp;Thank you for your reading-------</div>
    
</div>
      
    </div>
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Fitz
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://zhouyuqian.com/2020/03/30/ZYNQ-%E7%A7%BB%E6%A4%8D-Linux/" title="ZYNQ 移植 Linux">https://zhouyuqian.com/2020/03/30/ZYNQ-移植-Linux/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/FPGA/" <i class="fa fa-tag"></i> FPGA</a>
              <a href="/tags/ZYNQ/" <i class="fa fa-tag"></i> ZYNQ</a>
              <a href="/tags/Linux/" <i class="fa fa-tag"></i> Linux</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/03/27/RISC-V-SOC-Design-1/" rel="prev" title="RISC-V SOC Design (1)">
      <i class="fa fa-chevron-left"></i> RISC-V SOC Design (1)
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/04/04/Linux-Wake-on-Lan/" rel="next" title="Linux Wake on Lan">
      Linux Wake on Lan <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#vivado-%E5%B7%A5%E7%A8%8B%E5%88%9B%E5%BB%BA"><span class="nav-number">1.</span> <span class="nav-text">Vivado 工程创建</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E9%9C%80%E8%A6%81%E7%9A%84%E8%B5%84%E6%BA%90"><span class="nav-number">2.</span> <span class="nav-text">下载需要的资源</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83"><span class="nav-number">3.</span> <span class="nav-text">配置环境</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#build-device-tree-compiler-dtc"><span class="nav-number">3.1.</span> <span class="nav-text">Build Device Tree Compiler (dtc)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B6%E4%BB%96"><span class="nav-number">3.2.</span> <span class="nav-text">其他</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E8%AE%BE%E5%A4%87%E6%A0%91%E6%96%87%E4%BB%B6"><span class="nav-number">4.</span> <span class="nav-text">创建设备树文件</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%BC%96%E8%AF%91-u-boot-%E7%BC%96%E8%AF%91%E8%AE%BE%E5%A4%87%E6%A0%91"><span class="nav-number">5.</span> <span class="nav-text">编译 U-BOOT &amp; 编译设备树</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA-boot.bin"><span class="nav-number">6.</span> <span class="nav-text">创建 BOOT.bin</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8"><span class="nav-number">7.</span> <span class="nav-text">编译内核</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E6%96%87%E4%BB%B6"><span class="nav-number">8.</span> <span class="nav-text">环境变量文件</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%9C%80%E5%90%8E"><span class="nav-number">9.</span> <span class="nav-text">最后</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9D%91"><span class="nav-number">10.</span> <span class="nav-text">坑</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Fitz"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Fitz</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">52</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Starrynightzyq" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Starrynightzyq" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:starrynightzyq@gmail.com" title="E-Mail → mailto:starrynightzyq@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://space.bilibili.com/57711842" title="Bilibili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;57711842" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom bilibili"></i>Bilibili</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://wpa.qq.com/msgrd?v=3&uin=2421854978&site=qq&menu=yes" title="QQ → http:&#x2F;&#x2F;wpa.qq.com&#x2F;msgrd?v&#x3D;3&amp;uin&#x3D;2421854978&amp;site&#x3D;qq&amp;menu&#x3D;yes" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom qq"></i>QQ</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://leiblog.wang/" title="http:&#x2F;&#x2F;leiblog.wang" rel="noopener" target="_blank">Lei Blog</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        
  <div class="beian"><a href="http://beian.miit.gov.cn/" rel="noopener" target="_blank">苏ICP备20042287号 </a>
  </div>

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fitz</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">251k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:48</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.7.2
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.getAttribute('pjax') !== null) {
      script.setAttribute('pjax', '');
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

    </div>

  <!-- 页面点击小红心 -->
  <!-- <script type="text/javascript" src="/js/jquery-3.3.1.min.js"></script> -->
  <script type="text/javascript" src="/js/clicklove.js"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</body>
</html>
